using System;
using CodePlex.TfsLibrary;
using CodePlex.TfsLibrary.ObjectModel;
using CodePlex.TfsLibrary.Utility;

namespace CodePlex.CodePlexClientLibrary
{
    public class ApplyPatchConsoleView : IApplyPatchView
    {
        string basePath;
        readonly ApplyPatchPresenter presenter;

        public ApplyPatchConsoleView(IPatchEngine patchEngine,
                                     IFileSystem fileSystem)
        {
            presenter = new ApplyPatchPresenter(patchEngine, fileSystem, this);
        }

        public void Run(string directory,
                        string patchFilename)
        {
            basePath = directory;
            presenter.ApplyPatch(directory, patchFilename);
        }

        public void ShowStatus(SourceItem item,
                               SourceItemResult result)
        {
            if (result != SourceItemResult.S_Ok)
                ConsoleUtil.PrintCommandError(item.LocalName, result);
            else
                Console.WriteLine("Processing: {0}", CodePlexClientUtil.GetRelativePath(basePath, item.LocalName));
        }
    }
}